package com.music.adapter;

import java.util.ArrayList;

import com.music.R;
import com.music.utilbean.SearchResult;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class NetMusicListAdapter extends BaseAdapter{
private Context ctx;
private ArrayList<SearchResult>searchResults;
	public NetMusicListAdapter(Context ctx,
			ArrayList<SearchResult> searchResults) {
		this.ctx=ctx;
		this.searchResults=searchResults;
	}
public ArrayList<SearchResult> getSearchResults(){
	return searchResults;
}
public void setSearchResults(ArrayList<SearchResult> searchResults) {
	this.searchResults = searchResults;
}
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return searchResults.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return searchResults.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder vh;
		if(convertView==null){
			convertView=LayoutInflater.from(ctx).inflate(R.layout.item_net_list, null);
			vh=new ViewHolder();
			vh.net_title=(TextView) convertView.findViewById(R.id.net_title);
			vh.net_singer=(TextView) convertView.findViewById(R.id.net_singer);
			convertView.setTag(vh);
		}
		vh=(ViewHolder) convertView.getTag();
	SearchResult result=searchResults.get(position);
	vh.net_title.setText(result.getMusicname());
	vh.net_singer.setText(result.getArtist());
		return convertView;
	}
static class ViewHolder{
	TextView net_title;
	TextView net_singer;
}
}
